package com.ljy.cameralibrary.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * 照相机相框
 * Created by sky on 2015/7/7.
 */
public class CameraPhotoFrameView extends View {

    //    private Paint mPaint;
    private boolean showZheZhao = false;

    private Bitmap bitmap = null;

    public CameraPhotoFrameView(Context context) {
        this(context, null);
    }

    public CameraPhotoFrameView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        //        mPaint = new Paint();
        //        mPaint.setColor(Color.WHITE);
        //        mPaint.setAlpha(120);
        //        mPaint.setStrokeWidth(1f);
    }


    //画一个井字,上下画两条灰边，中间为正方形
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (showZheZhao) {
            RectF f = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
            if (bitmap != null) {
                canvas.drawBitmap(bitmap, null, f, null);
            }
        }

    }


    public void setZheZhao(boolean flag, Bitmap bitmap) {
        this.showZheZhao = flag;
        this.bitmap = bitmap;
        invalidate();
    }
}
